import sys

from loguru import logger
from starlette.requests import Request

config = {
    "handlers": [
        {"sink": sys.stdout, "colorize": True},
        {"sink": "file.log", "enqueue": True, "level": "ERROR", "rotation": "20 MB"}
    ]
}
logger.configure(**config)


def http(request: Request, response, time_s):
    """http请求日志"""
    logger.info(
        f'{request.method} {request.url.path} {response.status_code} {round(time_s * 1000, 3)} ms')


